package com.gz.controller;

import com.gz.common.RedisConst;
import com.gz.entity.China;
import com.gz.service.ChinaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/china")
public class ChinaController {
    @Autowired
    ChinaService chinaService;
    @Autowired
    private RedisTemplate redisTemplate;


    @GetMapping("/getProvinces")
    public ResponseEntity<?> getProvinces() {
        List<China> provinces = chinaService.getAddress(0, RedisConst.PROVINCES);
        System.out.println(provinces);
        return ResponseEntity.ok(provinces);
    }
    @GetMapping("/getCities/{provincePid}")
    public ResponseEntity<?> getCities(@PathVariable Integer provincePid) {
        List<China> cities = chinaService.getAddress(provincePid, RedisConst.CITIES+":"+provincePid);
        return ResponseEntity.ok(cities);
    }
    @GetMapping("/getDistricts/{cityPid}")
    public ResponseEntity<?> getDistricts(@PathVariable Integer cityPid) {
        List<China> districts = chinaService.getAddress(cityPid, RedisConst.DISTRICTS+":"+cityPid);
        return ResponseEntity.ok(districts);
    }

}
